//
//  UserDefaultsUtil.m
//  gdemm
//
//  Created by yongwu on 15/12/2.
//  Copyright © 2015年 goldensoft. All rights reserved.
//

#import "UserDefaultsUtil.h"

@implementation UserDefaultsUtil
NSUserDefaults *mDefaults;

- (instancetype)init
{
    
    if (self = [super init]) {
        mDefaults = [NSUserDefaults standardUserDefaults];
    }
    return self;
}

+(instancetype) shareInstance
{
    static UserDefaultsUtil* _instance = nil;
    static dispatch_once_t onceToken ;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc] init] ;
    }) ;

    return _instance ;
}



-(void)saveIntConfig:(NSString *)key :(int)value{
    [mDefaults setInteger:value forKey:key];
    [mDefaults synchronize];
}

-(void)saveBoolConfig:(NSString *)key :(BOOL)value{
    [mDefaults setBool:value forKey:key];
    [mDefaults synchronize];
}

-(void)saveObjectConfig:(NSString *)key :(NSObject *)value{
    [mDefaults setObject:value forKey:key];
    [mDefaults synchronize];
}

-(void)saveStringConfig:(NSString *)key :(NSString *)value{
    [self saveObjectConfig:key :value];
    
}

-(NSString*)getString:(NSString *)key{
    NSString *str = [mDefaults objectForKey:key];
    return str;
}

-(NSInteger)getInt:(NSString *)key{
    return [mDefaults integerForKey:key];
}

-(BOOL)getBool:(NSString *)key{
    return [mDefaults boolForKey:key];
}

-(NSObject*)getObject:(NSString *)key{
    return [mDefaults objectForKey:key];
}

-(void)saveFloatConfig:(NSString *)key :(float)value{
    [mDefaults setFloat:value forKey:key];
    [mDefaults synchronize];
}

-(float)getFloat:(NSString *)key{
    return [mDefaults floatForKey:key];
}
@end
